<style>
    .layui-form-pane .layui-form-label{width:auto;}
    .layui-form-item{margin-bottom: 0px;}
</style>
<div class="layui-form-item pt20 pl20 layui-form">
    <form class="layui-form"  action="{:url('')}"   id="form33" >
        <div id="tiao_num_add_content">
            {foreach $selectedData as $key=>$vo }
            <div class="layui-form-item" id="tiao_num_add_content_{$key}" >
                <label class="layui-form-label">选择尺码</label>
                <div class="layui-input-inline" id="xm_select_size_{$key}" style="min-width: 45%;">
                </div>
                <label class="layui-form-label">跳码</label>
                <div class="layui-input-inline">
                    <input type="text" name="tiao_num[]" value="{$vo.tiao_num}"  lay-verify="number" placeholder="输入跳码" class="layui-input">
                </div>
            </div>
            {/foreach}
            <div class=" layui-form-item">
                <label class="layui-form-label">是否自动选择尺码</label>
                <div class="layui-input-block">
                    <input type="radio" name="selected_type" value="1" title="是"  {if $selected_type == 1 }checked{/if}>
                    <input type="radio" name="selected_type" value="2" title="否" {if $selected_type == 2 }checked{/if}>
                </div>
            </div>
        </div>
        <div class="layui-inline fr" style="margin: 20px 20px;">
            <input type="hidden"  name="tr_num" value="{$tr_num}">
            <input type="hidden"  name="part" value="{$part}">
            <button type="button" class="layui-btn layui-btn-normal" id="submitSewingform">确定跳码</button>
            <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
        </div>
    </form>
</div>


{include file="system@block/layui" /}
<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/base64/base64.js?v={:config('hisiphp.version')}"></script>
<script type="text/javascript">
    {foreach $selectedData as $key=>$vo }
    var demo{$key} = xmSelect.render({
        el: '#xm_select_size_{$key}',
        name:'xm_select_size[]',
        language: 'zn',
        toolbar: {
            show: true,
        },
        filterable: true,
        data:{:json_encode($vo['xm_select_data'])},
    on: function(data){
        console.log(data);
        // size_rule_check(); //这个demo0.getValue()获取不及时
    }
    });
    {/foreach}
</script>
<script type="text/javascript">
    var can_submit=1;
    var trData=[];
    var layer = layui.layer;
    layui.use([ 'element', 'layer', 'laytpl', 'tool','laydate','table','form','flow'], function() {
        var element = layui.element;
        var layer = layui.layer;
        var $ = layui.jquery;
        var form = layui.form;
        var laytpl = layui.laytpl,laydate=layui.laydate ,table = layui.table;
        var flow = layui.flow;

    });

    //扩展jquery的格式化方法 变成 json 对象，然后直接扔给后台。 https://www.cnblogs.com/poterliu/p/10142758.html
    $.fn.parseForm=function(){
        var serializeObj={};
        var array=this.serializeArray();
        var str=this.serialize();
        $(array).each(function(){
            if(serializeObj[this.name]){
                if($.isArray(serializeObj[this.name])){
                    serializeObj[this.name].push(this.value);
                }else{
                    serializeObj[this.name]=[serializeObj[this.name],this.value];
                }
            }else{
                serializeObj[this.name]=this.value;
            }
        });
        return serializeObj;
    };

    $(document).on('click', '#submitSewingform',function(){
        size_rule_check();
        if(can_submit==2){
            layer.msg('数据选择有误', {icon: 2,anim: 6});
            return false;
        }
        // var d = JSON.parse($(this).attr('data-json'));
        $.ajax({
            type: "POST",
            url: "{:url('mp/Template/tiaoNumEdit')}",
            data: $("#form33").serialize(),
            dataType:"json",
            success: function(res){
                console.log(res);
            }
        });
        var data=$("#form33").parseForm();//serialize()
        parent.tiaoNumEdit(data);
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });
    size_rule_check();


    function size_rule_check(){
        trData=[{min:999999,max:-1},{min:999999,max:-1},{min:999999,max:-1},{min:999999,max:-1},{min:999999,max:-1}];
        if(demo0.getValue().length>0){
             $.each( demo0.getValue(), function(i, n){
                 if(n['data-order']<trData[0]['min']){
                     trData[0]['min']=n['data-order'];
                 }
                 if(n['data-order']>trData[0]['max']){
                     trData[0]['max']=n['data-order'];
                 }
             });
        }
        if(demo1.getValue().length>0){
            $.each( demo1.getValue(), function(i, n){
                if(n['data-order']<trData[1]['min']){
                    trData[1]['min']=n['data-order'];
                }
                if(n['data-order']>trData[1]['max']){
                    trData[1]['max']=n['data-order'];
                }
            });
        }
        if(demo2.getValue().length>0){
            $.each( demo2.getValue(), function(i, n){
                if(n['data-order']<trData[2]['min']){
                    trData[2]['min']=n['data-order'];
                }
                if(n['data-order']>trData[2]['max']){
                    trData[2]['max']=n['data-order'];
                }
            });
        }
        if(demo3.getValue().length>0){
            $.each( demo3.getValue(), function(i, n){
                if(n['data-order']<trData[3]['min']){
                    trData[3]['min']=n['data-order'];
                }
                if(n['data-order']>trData[3]['max']){
                    trData[3]['max']=n['data-order'];
                }
            });
        }
        if(demo4.getValue().length>0){
            $.each( demo4.getValue(), function(i, n){
                if(n['data-order']<trData[4]['min']){
                    trData[4]['min']=n['data-order'];
                }
                if(n['data-order']>trData[4]['max']){
                    trData[4]['max']=n['data-order'];
                }
            });
        }
        can_submit=1;
        $.each( trData, function(i, n){
            if(i<=3 && n.max>-1 && trData[i+1]['min']<999999  && n.max != trData[i+1]['min']  ){
                can_submit=2;
                layer.msg('选择尺码的选项不对', {icon: 2,anim: 6});
                return false;
            }
        });
    }
</script>